//
//  YBConst.h
//  YBNetworking
//
//  Created by ybgo on 2018/11/22.
//  Copyright © 2018 嘉联支付有限公司. All rights reserved.
//

#ifndef YBConst_h
#define YBConst_h

#define YB_SAFE_BLOCK(BlockName, ...) ({ !BlockName ? nil : BlockName(__VA_ARGS__); })
#define YBLock() dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER)
#define YBUnlock() dispatch_semaphore_signal(self->_lock)

NS_ASSUME_NONNULL_BEGIN

@class YBRequest;



typedef NS_ENUM(NSUInteger, YBRequestType) {
    kYBRequestNormal   = 0, //Normal HTTP request, such as GET,POST, ...
    kYBRequestUpload   = 1, //Upload request type
    kYBRequestDownload = 2, //Download request type
};

typedef NS_ENUM (NSUInteger, YBHTTPMethodType){
    YBHTTPMethodGET    = 0, // GET
    YBHTTPMethodPOST   = 1, // POST
    YBHTTPMethodHEAD   = 2, // HEAD
    YBHTTPMethodDELETE = 3, // DELETE
    YBHTTPMethodPUT    = 4, // PUT
    YBHTTPMethodPATCH  = 5, // PATCH
};

typedef NS_ENUM(NSUInteger, YBRequestParamatersType) {
    YBRequestParamatersTypeDictinary = 0,//NSDictionary类型数据
    YBRequestParamatersTypeData      = 1,//NSData类型数据
};

typedef NS_ENUM(NSUInteger, YBRequestSerializerType) {
    YBRequestSerializerRAW   = 0, //普通http编码方式 二进制 对应AFNetworking中'AFHTTPRequestSerializer',设置此格式需要将'Content-Type'的值设为'application/x-www-form-urlencoded'.
    YBRequestSerializerJSON  = 1, //json 编码格式 对应AFNetworking中'AFJSONRequestSerializer',设置此格式需要将'Content-Type'的值设为'application/json'.
    YBRequestSerializerPlist = 2, //plist 编码格式 对应AFNetworking中'AFPropertyListRequestSerializer',设置此格式需要将'Content-Type'的值设为'application/x-plist'.
};

typedef NS_ENUM(NSUInteger, YBResponseSerializerType) {
    YBResponseSerializerRAW   = 0, //Validates the response status code and content type, and returns the default response data.
    YBResponseSerializerJSON  = 1, //Validates and decodes JSON responses using `NSJSONSerialization`, and returns a NSDictionary/NSArray/... JSON object.
    YBResponseSerializerPlist = 2, //Validates and decodes Property List responses using `NSPropertyListSerialization`, and returns a property list object.
    YBResponseSerializerXML   = 3, //Validates and decodes XML responses as an `NSXMLParser` objects.
};

typedef NS_ENUM(NSUInteger, YBNetworkConnectionType) {
    YBNetworkConnectionTypeUnknown      = -1,
    YBNetworkConnectionTypeNotReachable = 0,
    YBNetworkConnectionTypeViaWWAN      = 1,
    YBNetworkConnectionTypeViaWiFi      = 2,
};


/**
 YBRequest Config Blocks
 */
typedef void(^YBRequestConfigBlock)(YBRequest *request);

/**
 YBRequest CallBack Blocks
 */
typedef void (^YBProgressBlock)(NSProgress *progress);
typedef void (^YBSuccessBlock)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject);
typedef void (^YBFailureBlock)(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error);
typedef void (^YBFinishedBlock)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject, NSError * _Nullable error);
typedef void (^YBCancelBlock)(id _Nullable request);

/**
 <#Description#>
 */
typedef void (^YBCenterRequestProcessBlock)(NSURLSessionDataTask * _Nullable task, YBRequest *request);

/**
 <#Description#>
 */
typedef id _Nullable (^YBCenterResponseProcessBlock)(NSURLSessionDataTask * _Nullable task, YBRequest *request, id _Nullable responseObject, NSError * _Nullable __autoreleasing *error);

/**
 <#Description#>
 */
typedef void (^YBCenterErrorProcessBlock)(NSURLSessionDataTask * _Nullable task, YBRequest *request, NSError * _Nullable __autoreleasing *error);

NS_ASSUME_NONNULL_END


#endif /* YBConst_h */
